package com.cloudsigns.factorymanager2.engineering.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.engineering.bean.MediaBean;
import com.cloudsigns.factorymanager2.engineering.bean.RegionBean;
import com.cloudsigns.factorymanager2.project.myinerface.ItemClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by tony on 2018/5/11.
 */

public class PublicationCompletionOrderMeidaForSuperAdapter extends BaseAdapter{
    private Context context;
    private List<MediaBean> datas = new ArrayList<MediaBean>();
    private LayoutInflater inflater;
    private ItemClickListener clickListener;
    private String tag = "";


    public PublicationCompletionOrderMeidaForSuperAdapter(Context context, String tag) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.tag = tag;

    }

    public void setData(List<MediaBean> list) {

        if (null != list) {
            this.datas.clear();
            this.datas.addAll(list);
        }

    }

    public void setItemClick(ItemClickListener clickListener) {
        this.clickListener = clickListener;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public MediaBean getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        final  ViewHolder holder;
        if (convertView == null) {
            holder = new  ViewHolder();

            convertView = inflater.inflate(R.layout.item_publication_completion_order_meidalist_for_super, null);
            holder.tv_project_name = convertView.findViewById(R.id.tv_project_name);
            holder.tv_engineering_name = convertView.findViewById(R.id.tv_engineering_name);

            holder.img_publication_before = convertView.findViewById(R.id.img_publication_before);
            holder.img_publication_behind = convertView.findViewById(R.id.img_publication_behind);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        MediaBean bean = datas.get(position);
//        holder.tv_project_name.setText(bean.getAreaName());
//        holder.tv_engineering_name.setText("/" + bean.getMediaName() + "/" + bean.getNumber());
        holder.tv_project_name.setText(bean.getMediaName());


        List<String> afterPicList = bean.getAfterPicList();
        List<String> beforePicList = bean.getBeforePicList();

        if(null != afterPicList && afterPicList.size() > 0){
            Uri uri = Uri.parse(afterPicList.get(0).toString().trim());
            Glide.with(context).load(uri).asBitmap().into(holder.img_publication_behind );

        }
        if(null != beforePicList && beforePicList.size() > 0){
            Uri uri = Uri.parse(beforePicList.get(0).toString().trim());
            Glide.with(context).load(uri).asBitmap().into(holder.img_publication_before );

        }


        return convertView;
    }

    private class ViewHolder {
        private TextView tv_project_name;
        private TextView tv_engineering_name;
        private ImageView img_publication_before;
        private ImageView img_publication_behind;
    }
}
